<template>
	<view>
		<text>是否开启定位，默认是关闭的：</text>
		<u-switch @change="isChecked" v-model="checked" active-color="red" inactive-color="#eee"></u-switch>
		
	</view>
	
</template>

<script>
	export default{
		data(){
			return{
				checked:false,
				user:{},
				
			}
		},
		
		
		

		methods:{
			isChecked(value){
				console.log(value)
				uni.showLoading({
					title:'更新中'
				})
				const id = getApp().globalData.user;
				
				//上传数据库
				const db = uniCloud.database();
				db.collection('users').doc(id._id).update({
					isLoc: value
				}).then(res=>{
					uni.hideLoading();
					uni.showToast({
						title:'更新成功'
					})
				}).catch(err=>{
					uni.hideLoading();
					uni.showToast({
						title:'更新失败',
						icon:'error'
					})
					this.value = false
					this.checked = false
					console.log(err)
				})
			},
			
			
		},
		
		
		
	}
</script>

<style>
</style>
